SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE PROCEDURE [dbo].[TvSeries_Get_TvSeriesInfo]
@Id INT
AS
--Declare @Id INT
--SET @Id = 1281
Select T.Id, T.Title, T.[Description], 
(Select Count(EpisodeId) From TvShow_Episodes E
join TvShow_Seasons S ON S.SeasonId = E.SeasonId
Where E.TvId = @Id AND Season <> 0) AS Episodes, 
		
(Select Count(SeasonId) From TvShow_Seasons 
Where TvId = @Id AND Season <> 0) AS Seasons,
T.Rating, T.ReleaseDate, T.[Status], T.BannerImage  
		
FROM tvshow_episodes E
inner join Tv T on T.Id = E.TvId
WHERE SeasonId <> 0 and E.rating <> -99 AND T.Id = @Id
Group By T.Id, T.Title, T.Rating, T.BannerImage, T.[Description], T.ReleaseDate, T.[Status]
GO
